<template>
	<view>
		<view v-if="gifts.length > 0">
		<view v-for="(subGifts,index) in gifts" :key="index">
			<view class='feedback-title'>
				<text>{{subGifts.createdStamp}}</text>
			</view>
			<view class="feedback-body feedback-uploader">
				<view class="uni-uploader">
					<view class="uni-uploader-body">
						<view class="uni-uploader__files">
							<block v-for="(item,index2) in subGifts.data" :key="index2">
								<view class="uni-uploader__file">
									<image class="uni-uploader__img" :src="item.originalImageUrl" @tap="previewImage"></image>
								</view>
							</block>
						</view>
					
					</view>
				</view>
			</view>
		</view>
		</view>
	</view>
</template>

<script>
	import {dateUtils} from '@/common/util'
	import {getGifts} from '@/api/ucenter/index'
	import {
		mapGetters,mapState 
	} from 'vuex'
	export default {
		data() {
			return {
				page: 1,
				pageSize: 100,
				gifts:[],
				imageList: []
			};
		},
		onLoad(e) {
			this.loadGift(e.partyId)
			if(e.partyId !== this.userId)
			{
				uni.setNavigationBarTitle({
					title: "她的礼物"
				})
			} else {
				uni.setNavigationBarTitle({
					title: "我的礼物"
				})
			}

		},
		computed:{
			...mapGetters(
				[ "hasLogin", "userId"]
			),
		},
		methods: {
			loadGift() {
				getGifts(this.getParameters()).then(response => {
					console.log(JSON.stringify(response));
					if(response.status == 200 && response.data.length > 0)  {
						var currArray = {};
						for(var i =0 ; i < response.data.length; i++) {
							var dataStr = dateUtils.format(response.data[i].createdStamp)
							if(currArray.createdStamp !== undefined)
							{
								currArray.createdStamp = dataStr;
								currArray.data = []
							}
							if(currArray.createdStamp == dataStr) {
								currArray.data.push(response.data[i])
							}
							else {
								gifts.push(currArray);
								currArray = {}
							}
						} 
					}
				});
			},
			getParameters(partyId) {
				return {
					page: this.page,
					limit: this.pageSize,
					toPartyId: partyId,
					orderBy: "createdStamp",
					sort: "desc"
				};
			},
			previewImage() { //预览图片
				uni.previewImage({
					urls: this.imageList
				});
			},
		}
		
	}
</script>

<style>

</style>
